package com.cloudcc.mobile.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.Message;
/**
 * 系统消息适配器
 * @author Administrator
 *
 */
public class MessageAdapter extends BaseAdapter{
	private List<Message> list;
	private Context context;
	public MessageAdapter(Context context,List<Message> list){
		this.list=list;
		this.context=context;
	}
	public void changeData(List<Message> list){
		this.list=list;
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Message getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;
		if(convertView==null){
			convertView=LayoutInflater.from(context).inflate(R.layout.message_list_item, null);
			holder=new ViewHolder();
			holder.name=(TextView)convertView.findViewById(R.id.name);
			holder.context=(TextView)convertView.findViewById(R.id.context);
			holder.time=(TextView)convertView.findViewById(R.id.time);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		Message message=getItem(position);
		holder.name.setText(message.getName());
		holder.time.setText(message.getTime());
		holder.context.setText(message.getContext());
		return convertView;
	}

	class ViewHolder{
		TextView name;
		TextView time;
		TextView context;
		
	}
}
